﻿using OSSUtility;
using OSSUtility.Models;
using Ozone.BLL;
using Ozone.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ozone.Views.SystemCenter.AdvancedParameter
{
    /// <summary>
    /// RobotByR300.xaml 的交互逻辑    旋蒸旁边机械臂
    /// </summary>
    public partial class RobotByR300 : UserControl
    {
        public RobotByR300()
        {
            InitializeComponent();
        }



        #region  机械臂操作
        /// <summary>
        /// 前后左右微调机械臂
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVolumeUp_click(object sender, RoutedEventArgs e)
        {

            double dStep = Utility.str2double(txt_Step.Text);
            int nSpeed = Utility.str2int(txt_Speed.Text);
            if (nSpeed < 10 || nSpeed > 100)
                nSpeed = 10;

            double dStepRoate = Utility.str2double(txt_StepRoate.Text);
            int nSpeedRoate = Utility.str2int(txt_SpeedRoate.Text);
            if (nSpeedRoate < 10 || nSpeedRoate > 300)
                nSpeedRoate = 10;

            PointXYZ po = DevRobotByR300.devRebot.GetCurPos();
            if (po == null)
            {
                return;
            }
            txt_CurPos.Text = po.X.ToString() + "," + po.Y.ToString() + "," + po.Z.ToString();

            string tag = ((Button)sender).Tag.ToString();
            if (tag == "x+")
            {
                po.X += dStep;
            }
            if (tag == "x-")
            {
                po.X -= dStep;
            }


            if (tag == "y+")
            {
                po.Y += dStep;
            }
            if (tag == "y-")
            {
                po.Y -= dStep;
            }


            if (tag == "z+")
            {
                po.Z += dStep;
            }
            if (tag == "z-")
            {
                po.Z -= dStep;
            }

            //旋转
            if (tag == "a+")
            {
                po.A += dStepRoate;
            }
            if (tag == "a-")
            {
                po.A -= dStepRoate;
            }

            if (tag == "b+")
            {
                po.B += dStepRoate;
            }
            if (tag == "b-")
            {
                po.B -= dStepRoate;
            }

            if (tag == "c+")
            {
                po.C += dStepRoate;
            }
            if (tag == "c-")
            {
                po.C -= dStepRoate;
            }

            bool b = DevRobotByR300.devRebot.MoveTo(po, nSpeed, nSpeedRoate, 1, 1000 * 100);

            if (!b)
                MessageBox.Show("移动失败");


        }










        int nWaitTime = 1000 * 1000;

        #endregion
        /// <summary>
        /// 装旋蒸瓶
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBeginPos_click(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 夹住旋蒸瓶
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHoldOnB_click(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 拆卸旋蒸瓶
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDismountB_click(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 旋蒸瓶放置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPlaceB_click(object sender, RoutedEventArgs e)
        {

        }
        /// <summary>
        /// 柱塞泵补液
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRotaryPumpFluidIn_click(object sender, RoutedEventArgs e)
        {
        }
        /// <summary>
        /// 停止柱塞泵补液
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStopRotaryPumpLuidIn_click(object sender, RoutedEventArgs e)
        {
        }

        private void btnReset_click(object sender, RoutedEventArgs e)
        {
        }

        private void btnPutReset_click(object sender, RoutedEventArgs e)
        {
        }

        private void btnRotaryInsertPipe_click(object sender, RoutedEventArgs e)
        {
        }

        private void btnOpenJaw_click(object sender, RoutedEventArgs e)
        {
            bool IsOk = DevRobotByR300.devRebot.UpDateTool("JawON", "", "", "", "", "", "");

        }

        private void btnCloseJaw_click(object sender, RoutedEventArgs e)
        {
            bool IsOk = DevRobotByR300.devRebot.UpDateTool("JawOFF", "", "", "", "", "", "");
        }

        private void btnBeginPtttyos_click(object sender, RoutedEventArgs e)
        {
            //移动轴
            string AxiePo = "134.418,49.2735,-93.2763,54.0935,65.6257,-28.2543";
            string[] ArryAxiePo = AxiePo.Split(',');
            string sAxie1 = ArryAxiePo[0];
            string sAxie2 = ArryAxiePo[1];
            string sAxie3 = ArryAxiePo[2];
            string sAxie4 = ArryAxiePo[3];
            string sAxie5 = ArryAxiePo[4];
            string sAxie6 = ArryAxiePo[5];
            if (!DevRobotByR300.devRebot.RunAxie(sAxie1, sAxie2, sAxie3, sAxie4, sAxie5, sAxie6, "50", "50", nWaitTime))
            {

            }
        }

        private void btnHeat_click(object sender, RoutedEventArgs e)
        {
            bool IsOk = DevRobotByR300.devRebot.UpDateTool("Heartbeat", "", "", "", "", "", "");

        }
    }
}
